<?php require_once("../includes/initializeSession.php"); ?>
<?php
if (!isset($_SESSION['admin'])) {
    header('Location: adminLogin.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php require_once("../includes/cssAndJsAdmin.php"); ?>
<script type="text/javascript">
    $(document).ready(function() {


// start checks jqgrid
                     $("#checksList").jqGrid({
                         url: "../gridFunctions/checksActions.php",
                         editurl: "../gridFunctions/checksActions.php",
                         direction: 'rtl',
                         async: false,
                         datatype: 'json',
                         pager: '#checksPager',
                         colNames: ['שורה','נוצר', 'מס מנוי', 'מס צק', 'מס חשבון', 'בנק', 'מס סניף', 'מס בנק', 'תאריך פירעון', 'סכום'],
                         colModel: [
                             {name: 'row_num', hidden: true, index: 'row_num', width: 60, editable: true, align: 'right'},
                              {name: 'create_2', index: 'create', width: 120, editable: true, align: 'right', editrules: {readonly: "readonly",required: true}},
                             {name: 'manuy2client_manuy_number', index: 'manuy2client_manuy_number', width: 60, editable: true, align: 'right', editrules: {readonly: "readonly", required: true, integer: true}},
                             {name: 'check_num', index: 'check_num', width: 120, editable: true, align: 'right', editrules: {required: true}},
                             {name: 'acount_num', index: 'acount_num', width: 120, editable: true, align: 'right', editrules: {required: true}},
                             {name: 'bank_name', index: 'bank_name', width: 120, editable: true, align: 'right', editrules: {required: true}},
                             {name: 'snif_number', index: 'snif_number', width: 70, editable: true, align: 'right', editrules: {required: true}},
                             {name: 'bank_num', index: 'bank_num', width: 70, editable: true, align: 'right', editrules: {required: true}},
                             {name: 'repayment_day', index: 'repayment_day', width: 80, editable: true, align: 'right', editrules: {required: true}},
                             {name: 'sum', index: 'sum', width: 60, editable: true, align: 'right', editrules: {required: true, integer: true}}],
                         rowNum: 20,
                         rowList: [5, 10, 20, 50],
                         sortname: 'row_num',
                         sortorder: "desc",
                         mtype: "POST",
                         postData: {oper: 'viewChecks'},
                         viewrecords: true,
                         imgpath: '../../Scripts/css/Aristo/images',
                         autowidth: true,
                         height: "100%"
                     }); // -- end of   $("#list").jqGrid({
         
                     $("#checksList").jqGrid('navGrid', '#checksPager', {edit: true, add: true, del: false, refresh: true, closeAfterAdd: true, reloadAfterSubmit: true, search: false},
                     // Edit dialog parameters
                     {
                         reloadAfterSubmit: true,
                         closeAfterEdit: true,
                         //editData: {person_number: function() {  return "7"; } },
                  afterShowForm: function() {
                     
                          if (!getSelectedCellManuim("person_number"))
                             {
                              
                                $.jgrid.hideModal("#editmodcashList", {gbox: "#gbox_cashList"});
                                alert("את חייב לבחו מנוי שאליו אתה רוצה להוסיף תשלום");
         
                             }
                     
                         },
                         beforeShowForm: function() {
                         if (getSelectedCellManuim("person_number"))
                        {
                            checkDate = $('#repayment_day');
                            checkDate.datepicker({
                                dateFormat: 'yy-mm-dd'
                            });
                            
                            $("#create_2").val(Date.today().toString('yyyy-MM-dd'));
                                 $("#create_2").attr("disabled", true)
                                 $("#manuy2client_manuy_number").attr("disabled", true);
                            
                        }
         
                         },
                         onclickSubmit: function(rp_ge, postdata)
                         {
                             //            return {person_number: getSelectedCell('person_number')};
                         },
                         afterSubmit: function(response, postdata)
                         {
                             if (response.responseText == "ok")
                             {
                                 success = true;
                                 alert("פרטי הצק התעדכנו בהצלחה")
                             }
                             else
                             {
         
                                 success = false;
                                 alert("פרטי הצק לא התעדכנו בהצלחה")
                             }
                             return [success, response.responseText]
                         }
                     },
                     // Add dialog parameters
                     {
                         reloadAfterSubmit: true,
                         closeAfterAdd: true,
                           afterShowForm: function() {
                     
                          if (!getSelectedCellManuim("person_number"))
                             {
                              
                                $.jgrid.hideModal("#editmodchecksList", {gbox: "#gbox_checksList"});
                                alert("אתה חייב לבחו מנוי שאליו אתה רוצה להוסיף תשלום");
         
                             }
                     
                         },
                         beforeShowForm: function() {
                     
                             if (getSelectedCellManuim("person_number"))
                             {
                             checkDate = $('#repayment_day');
                             checkDate.datepicker({
                                 dateFormat: 'yy-mm-dd'
                             });
                             $("#manuy2client_manuy_number").val(getSelectedCellManuim("manuy_number"));
                             // INSERT PREVE CHECK SETTEING
                             $("#check_num").val(  Number($("#checksList #1 td[aria-describedby='checksList_check_num']").text())+1) 
                             $("#acount_num").val(  $("#checksList #1 td[aria-describedby='checksList_acount_num']").text()) 
                             $("#bank_name").val(  $("#checksList #1 td[aria-describedby='checksList_bank_name']").text()) 
                             $("#snif_number").val(  $("#checksList #1 td[aria-describedby='checksList_snif_number']").text()) 
                             $("#bank_num").val(  $("#checksList #1 td[aria-describedby='checksList_bank_num']").text()) 
                             $("#repayment_day").val(Date.parse($("#checksList #1 td[aria-describedby='checksList_repayment_day']").text()).add(1).months().toString('yyyy-MM-dd')) 
                             $("#sum").val(  $("#checksList #1 td[aria-describedby='checksList_sum']").text()) 
         
                                $("#create_2").val(Date.today().toString('yyyy-MM-dd'));
                                 $("#create_2").attr("disabled", true)
                                 $("#manuy2client_manuy_number").attr("disabled", true);
         
         }

    },
                         onclickSubmit: function(rp_ge, postdata)
                         {
                             //            return {person_number: getSelectedCell('person_number')};
                         },
                         afterSubmit: function(response, postdata)
                         {
                             if (response.responseText == "ok")
                             {
                                 success = true;
                                 alert("פרטי הצק התווספו בהצלחה")
                             }
                             else
                             {
         
                                 success = false;
                                 alert("פרטי הצק לא התווספו בהצלחה")
                             }
                             return [success, response.responseText]
                         }
                     },
                     // Delete dialog parameters
                     {
                         reloadAfterSubmit: true,
                         onclickSubmit: function(rp_ge, postdata)
                         {
                             // return {person_number: getSelectedCell('person_number')};
                         },
                         afterSubmit: function(response, postdata) {
                             if (response.responseText == "ok")
                             {
                                 success = true;
                                 alert("צק נמחק בהצלחה")
                             }
                             else
                             {
                                 success = false;
                                 alert("צק לא נמחק בהצלחה")
                             }
                             return [success, response.responseText]
                         }
         
                     },
                     // Search dialog parameters
                     {},
                             // View dialog parameters
                                     {}
                             );
                             $('#checksList').jqGrid('filterToolbar', {searchOnEnter: true, enableClear: false});
         
                             // end checks jqgrid
         
    });// -- end of  $(document).ready(function ()
    function getSelectedCell(str)
    {
        var grid = jQuery('#list');
        var sel_id = grid.jqGrid('getGridParam', 'selrow');
        var myCellData = grid.jqGrid('getCell', sel_id, str);
        return myCellData;
    }
</script>
<title>ניהול צ'קים</title>
</head>
<body dir="rtl"  style="padding:0px; margin:0px;">
    <div id="main">
        <?php include("adminHeader.php"); ?>
        <h1>ניהול צ'קים </h1>
               <div id="lc">
                  <table id="checksList" class="scroll" cellpadding="0" cellspacing="0"></table>
                  <div id="checksPager" class="scroll" style="text-align: center;"> </div>
               </div>
        <?php include("../footer.php"); ?>	
    </div>
</body>
</html>